home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / aijournl / 1987_03 / logo.mar < prev   
Text File  |  1987-02-19  |  8KB  |  194 lines

  1.  
  2.  
  3.                       Learn LOGO Before LISP
  4.                          by Mike McMillan
  5.                   March 1987 issue of AI EXPERT
  6.  
  7.                       Sidebars 1, 2, and 3
  8.  
  9.  
  10. Sidebar 1
  11.  
  12. The following is a list of the LISP primitives,  predicates, 
  13. functions and their Logo equivalents. Those functions that do not 
  14. have  a  Logo  equivalent  have been noted.  Please remember that 
  15. most,  if not all,  of the LISP functions that are not duplicated 
  16. in Logo can be written in Logo. Logo is powerful enough to create 
  17. functions that behave like their LISP equivalents.
  18.  
  19.  
  20. The  LISP  function  is  listed first,  followed by the Logo 
  21. equivalent or N/A, meaning Logo does not have that function.
  22.  
  23.           CAR - FIRST                        GET - GETPROP
  24.  
  25.           CDR - BUTFIRST                     PUTPROP - PUTPROP
  26.  
  27.           CXXXR - FIRST BUTFIRST...BUTFIRST  REMPROP - REMPROP
  28.  
  29.           LAST - LAST                        PLIST - PLIST
  30.  
  31.           CONS - FPUT (FIRST PUT)            ATOM - WORDP
  32.  
  33.           APPEND - LPUT (LAST PUT)           NULL - EMPTYP
  34.  
  35.           LIST - LIST                        NUMBERP - NUMBERP
  36.  
  37.           NCONC - N/A (NCONC IN EXPERLOGO)   SYMBOLP - N/A
  38.  
  39.           RPLACA - N/A (RPLACA IN EXPERLOGO) LISTP - LISTP
  40.  
  41.           RPLACD - N/A (RPLACD IN EXPERLOGO) EQUAL - EQUALP
  42.  
  43.           NREVERSE - N/A                     MEMBER - MEMBERP
  44.  
  45.           ASSOC - N/A (FINDKEY IN EXPERLOGO) GREATERP - GREATERP
  46.  
  47.           LENGTH - COUNT                     LESSP - LESSP
  48.  
  49.           REVERSE - N/A(REVERSE IN EXPERLOGO)ZEROP - N/A
  50.  
  51.           SUBST - N/A (SUBST IN EXPERLOGO)   MINUSP - N/A
  52.  
  53.           LCONC - N/A                        PLUSP - N/A
  54.  
  55.           TCONC - N/A                        EVENP - N/A
  56.  
  57.           SETQ - MAKE                        ODDP - N/A
  58.  
  59.           SETF - N/A                         COND - IF
  60.  
  61.           SET - N/A                          IF - IF
  62.  
  63.           DEFUN - TO
  64.  
  65. This is not an exhaustive list; several of the more  compli-cated 
  66. or lesser-used LISP  functions  have  been  left  out.  The 
  67. reader should see from this list,  though,  just how much of LISP 
  68. has been implemented in Logo.
  69.  
  70.  
  71.  
  72. Sidebar 2
  73. Writing LISP Functions in Logo
  74.  
  75. Many of the LISP primitives  and  predicates  that  are  not 
  76. duplicated  in  Logo  can  be written in Logo.  Logo's power as a 
  77. symbolic computation language allows the programmer to do this.
  78.  
  79. For example,  in LISP there is a powerful  primitive  called 
  80. ASSOC. ASSOC looks for a key that is part of an association list. 
  81. For example, if we set up the following association:
  82.  
  83.                     (SETQ 'JANE '((OCCUPATION STUDENT)
  84.                                  (MAJOR COMPUTER-SCIENCE)
  85.                                  (LANGUAGE LISP)))
  86.  
  87.  
  88. ASSOC can retrieve the information we have set up.
  89.  
  90. Writing in LISP: (ASSOC 'LANGUAGE SALLY),  the computer will 
  91. respond: (LANGUAGE LISP).
  92.  
  93. ASSOC is not defined in Logo. It is,  however,  very easy to 
  94. create.  We  set  up  the  association  by  writing:  MAKE "SALLY 
  95. [[OCCUPATION STUDENT] [MAJOR COMPUTER.SCIENCE] [LANGUAGE  LISP]]. 
  96. We define the ASSOC primitive as follows:
  97.  
  98.                     TO ASSOC :KEY :OBJECT
  99.                     IF EMPTYP :OBJECT [OUTPUT "? STOP]
  100.                     IF  EQUALP  FIRST  FIRST  :OBJECT  :KEY  [OUTPUT  FIRST
  101.           :OBJECT STOP]
  102.                     OUTPUT ASSOC :KEY BF :OBJECT
  103.                     END
  104.  
  105. Our Logo ASSOC goes through the  association  list    recur-
  106. sively,  checking  each  key  to  see  if it matches the argument 
  107. given.  If there is nothing in the association  list,  or  if  it 
  108. cannot  find a match,  ASSOC will output a question mark.  When a 
  109. match is found, the key and the object are output and the  proce-
  110. dure stops.
  111.  
  112. ASSOC is a fairly complicated example.  Several of the  LISP 
  113. primitives  that  do  not have Logo equivalents can be defined in 
  114. one or two lines of Logo code.  For example,  to define the  Logo 
  115. version of LISP's ZEROP, we write:
  116.  
  117.                     TO MY-ZEROP: NUMBER
  118.                     IF EQUALP :NUMBER "0 [OUTPUT "TRUE]
  119.                     IF  EQUALP  LAST  :NUMBER  "0  [OUTPUT  "TRUE]  [OUTPUT
  120.           "FALSE]
  121.                     END
  122.  
  123. The extensibility of Logo is helpful in the study  of  LISP. the  
  124. student  trying to model LISP expressions in Logo will often need 
  125. to write LISP primitives and predicates in Logo in order  to use 
  126. them. I found in my own study that writing a LISP function in 
  127. Logo gave me a deeper understanding of that function.  It takes a 
  128. higher magnitude of understanding to write  a  function  than  it 
  129. does just to use the function.
  130.  
  131.  
  132.  
  133. Sidebar 3
  134. ExperLogo - A LISP-like Logo
  135.  
  136. One  version of Logo stands out from the others as being the most 
  137. LISP-like in its form and structure - ExperLogo from  Exper-
  138. Telligence.  ExperLogo's LISPness is apparent in  several    dif-
  139. ferent  areas - from its rules of evaluation to its toolchest  of 
  140. primitives and predicates.
  141.  
  142. The first noticeable LISP-like feature of ExperLogo  is  the way  
  143. it evaluates its expressions.  In ExperLogo every expression is 
  144. evaluated,  meaning that primitives and predicates will  print 
  145. the  results  of  their evaluation on the screen without the need 
  146. for a PRINT command.  This element of first-classness is an   im-
  147. portant  feature  of  LISP  that is not found in most versions of 
  148. Logo.
  149.  
  150. For example,  in most Logos to print the value of a variable the  
  151. variable  has  to be combined with a PRINT command,  such as 
  152. PRINT :PEOPLE.  In ExperLogo only the variable has to be written, 
  153. as  in  :PEOPLE,  which  is much like the way it would be done in 
  154. LISP - (PEOPLE).
  155.  
  156. ExperLogo is also more LISP-like in the way values are bound to 
  157. variables.  In most Logos a value is bound to  a  variable  by 
  158. writing  MAKE  "NAME "TOM.  In ExperLogo you can write: MAKE NAME 
  159. TOM. In LISP it would be (SETQ NAME TOM).
  160.  
  161. Expressions that evaluate to  true  or  false  in  ExperLogo 
  162. return values in the same manner as LISP,  either T or NIL, which 
  163. is unlike most Logos, which return TRUE or FALSE.
  164.  
  165. Another area of ExperLogo that makes  it  so  comparable  to LISP 
  166. is its expanded list of LISP-like primitives and predicates. In  
  167. most  versions  of  Logo  there is not a primitive similar to 
  168. LISP's REVERSE,  which takes the elements of a list  and  reverse 
  169. their order. ExperLogo has REVERSE.
  170.  
  171. In LISP the primitive SUBST is used to substitute a new  ex-
  172. pression  for an old expression in some target expression,  say a 
  173. list.  Most versions of Logo do not have this powerful primitive; 
  174. ExperLogo does.
  175.  
  176. A  very  powerful  primitive  in LISP is ASSOC (discussed in 
  177. another sidebar).  Most Logos do not have this primitive,  though 
  178. it  can  be  written in Logo.  ExperLogo has this primitive under 
  179. another name - FINDKEY. FINDKEY works just like ASSOC; it takes a 
  180. key word (atom) and an expression as arguments and then finds the 
  181. element that goes with the key.
  182.  
  183. Here is a list of functions in ExperLogo which are not found in 
  184. other Logos but can be found in LISP: ELEMS,  FINDKEY,  NCONC, 
  185. NPUT,  PAIRLIST,  REMOVE,  REVERSE, RPLACA, RPLACD, SORT, SORTKEY 
  186. and SUBST.  Some of these functions do not duplicate  their  LISP 
  187. equivalent's  name,  but in following the Logo tradition are more 
  188. mnemonic, hence easier to remember and understand.
  189.  
  190. ExperLogo at this time is available only for the  Macintosh, but  
  191. if  you  have  a  Mac and are looking for a Logo with a high 
  192. degree of LISP similarity,  I would highly recommend  looking  at 
  193. this excellent Logo implementation.
  194.